package org.example.computerdesign.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import org.example.computerdesign.common.RespBody;
import org.example.computerdesign.domain.dto.LoginBody;
import org.example.computerdesign.domain.dto.RegisterBody;
import org.example.computerdesign.exception.ServiceException;
import org.example.computerdesign.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
 * @author 朱文权
 * */
@RestController
public class DoctorController {
    @Autowired
    private DoctorService doctorService;
    @PostMapping("login")
    public RespBody<?> login(@RequestBody @Validated LoginBody loginBody){
        return RespBody.success(doctorService.login(loginBody.getEmail(),loginBody.getPassword()));
    }
    @PostMapping("register")
    public RespBody<?> register(@RequestBody @Validated RegisterBody registerBody){
        doctorService.register(registerBody.getEmail(),registerBody.getPassword(),registerBody.getCode());
        return RespBody.success();
    }
    @SaCheckLogin
    @GetMapping("doctorCenter")
    public RespBody<?> getDoctorInfo(){
        Long id=StpUtil.getLoginIdAsLong();
        return RespBody.success(doctorService.getDoctorInfo(id));
    }
}
